<?php
// application/models/UsersTable.php
/**
 * Model_UsersTable
 *
 * demo-zf application
 *
 * @author Adam Pilacki <adam.pilacki@gmail.com>
 * @version 1.0.0
 */

final class Model_UsersTable
    extends AdamP_Model_TableAbstract
{
    /**
     * Connection name
     */
    protected $_connectionName = 'default';

    /**
     * Db table name
     */
    protected $_name = 'users';

    /**
     * Row class name
     */
    protected $_rowClass = 'Model_UsersRow';


    /**
     * Finds users object by auth props and returns it
     *
     * @param string $login
     * @param string $password
     * @return Model_UsersRow|null
     */
    public final function findOneByAuthProperties($login, $password)
    {
        return $this->fetchRow(
            $this->select()
                ->where('login = ?', $login, 'string')
                ->where('password = ?', sha1($password))
        );
    }

    /**
     * Finds users object by login and returns it
     *
     * @param string $login
     * @param string $password
     * @return Model_UsersRow|null
     */
    public final function findOneByLogin($login)
    {
        return $this->fetchRow(
            $this->select()
                ->where('login = ?', $login, 'string')
        );
    }
}